gsk: Avoid using gtk css types in public api
authorMatthias Clasen <mclasen@redhat.com>
Tue, 17 Nov 2020 03:21:27 +0000 (22:21 -0500)
committerMatthias Clasen <mclasen@redhat.com>
Tue, 17 Nov 2020 04:27:44 +0000 (23:27 -0500)
Using GtkCssSection in public headers here may be
ok from the C perspective, since it all ends up in
the same library anyway. But it causes circular
dependency problems for our gir files that are still
split by namespace.

To avoid this problem, copy the GtkCssLocation struct
struct as GskParseLocation, and pass take two of them
instead of a GtkCssSection in the error callback.

Update all users.

Fixes: #2454
demos/node-editor/node-editor-window.c
gsk/gskrendernode.h
gsk/gskrendernodeparser.c
tests/rendernode.c
tests/showrendernode.c
testsuite/gsk/compare-render.c
testsuite/gsk/node-parser.c

index 73cf2b06ecc13e03daa092446ca707091c91f276..ff536d60ca85438b2d70ba51ea5e60903171f8ad 100644 (file)
@@ -102,12 +102,11 @@ text_buffer_remove_all_tags (GtkTextBuffer *buffer)
 }
 
 static void
-deserialize_error_func (const GtkCssSection *section,
-                        const GError        *error,
-                        gpointer             user_data)
+deserialize_error_func (const GskParseLocation *start_location,
+                        const GskParseLocation *end_location,
+                        const GError           *error,
+                        gpointer                user_data)
 {
-  const GtkCssLocation *start_location = gtk_css_section_get_start_location (section);
-  const GtkCssLocation *end_location = gtk_css_section_get_end_location (section);
   NodeEditorWindow *self = user_data;
   GtkTextIter start_iter, end_iter;
   TextViewError text_view_error;
index dd655d3b358cb1ed283192826b913d97be7f377a..683bf5d9ff359136a9876eded5ad2d00f96614bb 100644 (file)
@@ -54,18 +54,31 @@ struct _GskShadow
   float radius;
 };
 
+typedef struct _GskParseLocation GskParseLocation;
+
+struct _GskParseLocation
+{
+  gsize bytes;
+  gsize chars;
+  gsize lines;
+  gsize line_bytes;
+  gsize line_chars;
+};
+
 /**
  * GskParseErrorFunc:
- * @section: the #GtkCssSection where the error occurred
- * @error:  the error
+ * @start: start of the error location
+ * @end: end of the error location
+ * @error: the error
  * @user_data: user data
  *
  * The type of callback that is called when a parse error occurs
  * during deserialization of node data.
  */
-typedef void           (* GskParseErrorFunc)                    (const GtkCssSection *section,
-                                                                 const GError        *error,
-                                                                 gpointer             user_data);
+typedef void           (* GskParseErrorFunc)                    (const GskParseLocation *start,
+                                                                 const GskParseLocation *end,
+                                                                 const GError           *error,
+                                                                 gpointer                user_data);
 
 GDK_AVAILABLE_IN_ALL
 GType                   gsk_render_node_get_type                (void) G_GNUC_CONST;
index 320f74a13ccc106f5a398958a9708ee6c53ec497..2be0a553935c48d78d693c2df2bf96af33f95dda 100644 (file)
@@ -1859,12 +1859,10 @@ gsk_render_node_parser_error (GtkCssParser         *parser,
   } *error_func_pair = user_data;
 
   if (error_func_pair->error_func)
-    {
-      GtkCssSection *section = gtk_css_section_new (gtk_css_parser_get_file (parser), start, end);
-
-      error_func_pair->error_func (section, error, error_func_pair->user_data);
-      gtk_css_section_unref (section);
-    }
+    error_func_pair->error_func ((const GskParseLocation *)start,
+                                 (const GskParseLocation *)end,
+                                 error,
+                                 error_func_pair->user_data);
 }
 
 GskRenderNode *
index 786cc6d050ca26049df8ab3361d0d0205a906a43..d0e32306633ea0f7b0de1dd803efc7ad92754c97 100644 (file)
@@ -14,15 +14,26 @@ static GOptionEntry options[] = {
 };
 
 static void
-deserialize_error_func (const GtkCssSection *section,
-                        const GError        *error,
-                        gpointer             user_data)
+deserialize_error_func (const GskParseLocation *start,
+                        const GskParseLocation *end,
+                        const GError           *error,
+                        gpointer                user_data)
 {
-  char *section_str = gtk_css_section_to_string (section);
+  GString *string = g_string_new ("<data>");
 
-  g_warning ("Error at %s: %s", section_str, error->message);
+  g_string_append_printf (string, ":%zu:%zu",
+                          start->lines + 1, start->line_chars + 1);
+  if (start->lines != end->lines || start->line_chars != end->line_chars)
+    {
+      g_string_append (string, "-");
+      if (start->lines != end->lines)
+        g_string_append_printf (string, "%zu:", end->lines + 1);
+      g_string_append_printf (string, "%zu", end->line_chars + 1);
+    }
+
+  g_warning ("Error at %s: %s", string->str, error->message);
 
-  g_free (section_str);
+  g_string_free (string, TRUE);
 }
 
 
index 92bc6d40eb0dd2f325beac4873ad78be86cb5263..5fafd3c00ef9f13f92dbd5f76abd10ffd4f0a2ef 100644 (file)
@@ -102,15 +102,26 @@ gtk_node_view_class_init (GtkNodeViewClass *klass)
 }
 
 static void
-deserialize_error_func (const GtkCssSection *section,
-                        const GError        *error,
-                        gpointer             user_data)
+deserialize_error_func (const GskParseLocation *start,
+                        const GskParseLocation *end,
+                        const GError           *error,
+                        gpointer                user_data)
 {
-  char *section_str = gtk_css_section_to_string (section);
+  GString *string = g_string_new ("<data>");
 
-  g_warning ("Error at %s: %s", section_str, error->message);
+  g_string_append_printf (string, ":%zu:%zu",
+                          start->lines + 1, start->line_chars + 1);
+  if (start->lines != end->lines || start->line_chars != end->line_chars)
+    {
+      g_string_append (string, "-");
+      if (start->lines != end->lines)
+        g_string_append_printf (string, "%zu:", end->lines + 1);
+      g_string_append_printf (string, "%zu", end->line_chars + 1);
+    }
+
+  g_warning ("Error at %s: %s", string->str, error->message);
 
-  g_free (section_str);
+  g_string_free (string, TRUE);
 }
 
 static void
index c71ee55b7c09eeabe3ffb764d74fc5b5b8aefb09..562a82e5d769f36003c46186488942b44a0cde42 100644 (file)
@@ -111,16 +111,26 @@ save_image (cairo_surface_t *surface,
 }
 
 static void
-deserialize_error_func (const GtkCssSection *section,
-                        const GError        *error,
-                        gpointer             user_data)
+deserialize_error_func (const GskParseLocation *start,
+                        const GskParseLocation *end,
+                        const GError           *error,
+                        gpointer                user_data)
 {
-  char *section_str = gtk_css_section_to_string (section);
+  GString *string = g_string_new ("<data>");
 
-  g_print ("Error at %s: %s", section_str, error->message);
-  *((gboolean *) user_data) = FALSE;
+  g_string_append_printf (string, ":%zu:%zu",
+                          start->lines + 1, start->line_chars + 1);
+  if (start->lines != end->lines || start->line_chars != end->line_chars)
+    {
+      g_string_append (string, "-");
+      if (start->lines != end->lines)
+        g_string_append_printf (string, "%zu:", end->lines + 1);
+      g_string_append_printf (string, "%zu", end->line_chars + 1);
+    }
+
+  g_warning ("Error at %s: %s", string->str, error->message);
 
-  free (section_str);
+  g_string_free (string, TRUE);
 }
 
 static const GOptionEntry options[] = {
index cd3c9304616f5fdf6fe3150008ff2f7c4587bea8..e7cf97887e43cdde2712ceb6d55f5958bdb9a861 100644 (file)
@@ -122,19 +122,26 @@ append_error_value (GString *string,
 }
 
 static void
-deserialize_error_func (const GtkCssSection *section,
-                        const GError        *error,
-                        gpointer             user_data)
+deserialize_error_func (const GskParseLocation *start,
+                        const GskParseLocation *end,
+                        const GError           *error,
+                        gpointer                user_data)
 {
   GString *errors = user_data;
-  char *section_string;
+  GString *string = g_string_new ("<data>");
 
-  section_string = gtk_css_section_to_string (section);
+  g_string_append_printf (string, ":%zu:%zu",
+                          start->lines + 1, start->line_chars + 1);
+  if (start->lines != end->lines || start->line_chars != end->line_chars)
+    {
+      g_string_append (string, "-");
+      if (start->lines != end->lines)
+        g_string_append_printf (string, "%zu:", end->lines + 1);
+      g_string_append_printf (string, "%zu", end->line_chars + 1);
+    }
 
-  g_string_append_printf (errors,
-                          "%s: error: ",
-                          section_string);
-  g_free (section_string);
+  g_string_append_printf (errors, "%s: error: ", string->str);
+  g_string_free (string, TRUE);
 
   if (error->domain == GTK_CSS_PARSER_ERROR)
     append_error_value (errors, GTK_TYPE_CSS_PARSER_ERROR, error->code);